package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    //查询今日新用户注册数或者今日登录次数
    @Select("select count(distinct user_id) from tb_log where type=#{type} and log_time=#{today}")
    Integer selectByType(@Param("type") String type,@Param("today") String today);

    //查询今日活跃用户数
    @Select("select count(distinct user_id) from tb_log where log_time=#{today}")
    Integer selectNumActive(String today);

    //查询次日留存
    @Select("select count(distinct user_id) from tb_log where log_time=#{today} and user_id in \n" +
            "(select user_id from tb_log where log_time=#{yesterday} and type='0102')")
    Integer selectNumRetention1d(@Param("today") String today,@Param("yesterday") String yesterday);
}